<template>
  <div class="register-page">
    <!-- 导航栏 -->
    <van-nav-bar title="面经注册" />
    <!-- 表单 -->
    <van-form @submit="onSubmit">
      <van-field
        v-model="user.username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="rules.username"
      />
      <van-field
        v-model="user.password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="rules.password"
      />
      <div style="margin: 16px;">
        <van-button block type="primary" native-type="submit">注册</van-button>
      </div>
    </van-form>
    <!-- router-link -->
    <router-link class="link" to="/login">有账号，去登录</router-link>
  </div>
</template>

<script>
export default {
  name: 'register-page',
  data () {
    return {
      user: {
        username: '',
        password: ''
      },

      rules: {
        username: [
          { required: true, message: '请填写用户名' },
          // \w 是代表字母、数字、下划线
          // {5,} 至少5位
          { pattern: /^\w{5,}$/, message: '用户名至少5位' }
        ],

        password: [
          { required: true, message: '请填写密码' },
          { pattern: /^\w{6,}$/, message: '密码至少6位' }
        ]
      }
    }
  },
  methods: {
    // 当这个事件触发的时候，绝对已经通过校验了
    onSubmit () {
      
      // 拿到输入内容，发请求去做注册，根据返回的结果做处理
    }
  }
}
</script>

<style lang="less" scoped>
.link {
  color: #069;
  font-size: 12px;
  padding-right: 20px;
  float: right;
}
</style>
